package br.com.sige.session;

import java.util.ArrayList;
import java.util.List;

import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

import br.com.sige.contratoEjb.StandardContrato;
import br.com.sige.entidade.Standard;

@Stateless
public class StandardSession implements StandardContrato {

	@PersistenceContext
	private EntityManager em;

	@Override
	public void salvar(Standard standard) {
		em.merge(standard);
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<Standard> listarStandard() {
		List<Standard> standard = new ArrayList<Standard>();
		Query query = em.createQuery("SELECT p FROM Standard p");
		standard = query.getResultList();
		return standard;
	}
	
	@Override 
	public void excluir(Standard standard) {
		standard = em.find(Standard.class, standard.getId());
		em.remove(standard);		
	}
}
